package tests;

import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class MyQuestionBankPage extends Utils {
    public static String url = "http://49.235.61.184:8080/repo/index";

    public MyQuestionBankPage() {
        super(url);
    }
    /**
     * 检查页面元素
     */
    public void checkMyQuestionBankPageRight() throws IOException {
        //检查页面标题
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > nav > ol > li:nth-child(3) > span.ant-breadcrumb-link > span"));
        //检查名称输入框
        driver.findElement(By.cssSelector("#name"));
        //检查类型选择框
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(2) > div > div > div.ant-col.ant-form-item-control > div > div > div > div"));
        //检查“重置”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(3) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(1) > button"));
        //检查“查询”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(3) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(2) > button"));
        //检查“新建”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-pro-table-list-toolbar > div > div.ant-space.ant-space-horizontal.ant-space-align-center.ant-pro-table-list-toolbar-right > div:nth-child(1) > div > div > button"));
        //检查“文本导入”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-table-wrapper > div > div > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(9) > div > div:nth-child(1) > a"));
        //检查“模板导入”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-table-wrapper > div > div > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(9) > div > div:nth-child(2) > a"));
        //检查“试题管理”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-table-wrapper > div > div > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(9) > div > div:nth-child(3) > a"));
        //检查“...”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-table-wrapper > div > div > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(9) > div > div:nth-child(4) > a"));
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }
    /**
     * 测试一：新建题库和查询
     */
    public void createQuestionBank() throws IOException, InterruptedException {
        //新建
        //点击“新建”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-pro-table-list-toolbar > div > div.ant-space.ant-space-horizontal.ant-space-align-center.ant-pro-table-list-toolbar-right > div:nth-child(1) > div > div > button")).click();
        Thread.sleep(2000);
        //输入题库名称
        /*driver.findElement(By.cssSelector("#name")).sendKeys("自动化测试");*/
        driver.findElement(By.xpath("//input[@placeholder=\"请输入题库名称\"]")).sendKeys("自动化测试");
        Thread.sleep(2000);
        //选择题库类型
        driver.findElement(By.xpath("//div[contains(@class, 'ant-drawer')]//*[@id='mode']")).click();
        Thread.sleep(1000);
        driver.findElement( By.xpath("//div[contains(@class, 'ant-drawer')]//*[text()='问卷']")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //点击”确定“按钮
        driver.findElement(By.cssSelector("body > div:nth-child(7) > div > div.ant-drawer-content-wrapper > div > div > div.ant-drawer-footer > div > div > div:nth-child(2) > button")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //查询
        //输入新建题库的名字
        Thread.sleep(1000);
        driver.findElement(By.cssSelector("#name")).sendKeys("自动化测试");
        //点击“查询”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div > main > div > div.ant-pro-grid-content > div > div > div > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(3) > div > div > div.ant-col.ant-form-item-control > div > div > div > div:nth-child(1) > div > div:nth-child(2) > button")).click();
        Thread.sleep(1000);
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //获取新建题库的名称
        String str = driver.findElement(By.xpath("//td[@title='自动化测试']")).getAttribute("title");
        assert str.equals("自动化测试");
    }

    /**
     * 测试二：重置
     */
    public void reset() throws IOException, InterruptedException {
        //点击“重置”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(3) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(1) > button")).click();
        Thread.sleep(1000);
        //获取第一个题库的标签
        String str = driver.findElement(By.cssSelector("#sk-layout > div > div > section > div > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-table-wrapper > div > div > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(7) > span")).getText();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        assert str.equals("123");
        String str1 = driver.findElement(By.cssSelector("#name")).getText();
        assert str1.equals("");

    }

}
